core: Add from-file argument to compose
authorColin Walters <walters@verbum.org>
Tue, 10 Jan 2012 23:55:00 +0000 (18:55 -0500)
committerColin Walters <walters@verbum.org>
Tue, 10 Jan 2012 23:55:00 +0000 (18:55 -0500)
We don't want to have to pass a million arguments.

src/ostree/ot-builtin-compose.c
tests/t0004-compose.sh

index 3fc18b360fa2d9a2ee17e912c12ac347ddc37732..9bbc915ae198def883f4ba9248c627b680a26c30 100644 (file)
 static char *subject;
 static char *body;
 static char *branch;
+static char *from_file_path;
 static gboolean recompose;
 
 static GOptionEntry options[] = {
   { "subject", 's', 0, G_OPTION_ARG_STRING, &subject, "One line subject", "subject" },
   { "body", 'm', 0, G_OPTION_ARG_STRING, &body, "Full description", "body" },
   { "branch", 'b', 0, G_OPTION_ARG_STRING, &branch, "Branch", "branch" },
+  { "from-file", 'F', 0, G_OPTION_ARG_STRING, &from_file_path, "Take list of branches to compose from FILE", "FILE" },
   { "recompose", 0, 0, G_OPTION_ARG_NONE, &recompose, "Regenerate compose from existing branches", NULL },
   { NULL }
 };
@@ -92,6 +94,9 @@ ostree_builtin_compose (int argc, char **argv, GFile *repo_path, GError **error)
   char *commit_checksum = NULL;
   GCancellable *cancellable = NULL;
   GFile *metadata_f = NULL;
+  GFile *from_file = NULL;
+  char *from_file_contents = NULL;
+  char **from_file_args = NULL;
   OstreeMutableTree *mtree = NULL;
   gboolean skip_commit = FALSE;
   gboolean in_transaction = FALSE;
@@ -177,6 +182,31 @@ ostree_builtin_compose (int argc, char **argv, GFile *repo_path, GError **error)
           g_hash_table_insert (seen_branches, g_strdup (branch_name), (char*)branch_name);
         }
     }
+
+  if (from_file_path)
+    {
+      char **iter;
+
+      from_file = ot_gfile_new_for_path (from_file_path);
+      if (!ot_gfile_load_contents_utf8 (from_file,
+                                        &from_file_contents, NULL, NULL, error))
+        goto out;
+      
+      from_file_args = g_strsplit_set (from_file_contents, "\n", -1);
+
+      for (iter = from_file_args; *iter && **iter; iter++)
+        {
+          const char *src_branch = *iter;
+
+          if (seen_branches && g_hash_table_lookup (seen_branches, src_branch))
+            continue;
+          
+          if (!add_branch (repo, mtree, src_branch,
+                           &compose_metadata_builder,
+                           error))
+            goto out;
+        }
+    }
   
   for (i = 1; i < argc; i++)
     {
@@ -272,5 +302,8 @@ ostree_builtin_compose (int argc, char **argv, GFile *repo_path, GError **error)
   g_clear_object (&destf);
   g_clear_object (&metadata_f);
   g_clear_object (&mtree);
+  g_clear_object (&from_file);
+  g_free (from_file_contents);
+  g_strfreev (from_file_args);
   return ret;
 }
index 5014c00daf966047838111cad920fa5e8ca488df..8ec351e0e0dee94dbf7d6e5f74a56b2e91643d85 100755 (executable)
@@ -19,7 +19,7 @@
 
 set -e
 
-echo "1..7"
+echo "1..8"
 
 . libtest.sh
 
@@ -99,3 +99,14 @@ $OSTREE checkout some-compose some-compose-checkout
 cd some-compose-checkout
 assert_file_has_content ./usr/bin/bar 'updated bar ELF file'
 echo 'ok recompose with args'
+
+cd "${test_tmpdir}"
+echo artifact-libfoo-runtime > compose-contents.txt
+echo artifact-libfoo-devel >> compose-contents.txt
+echo artifact-barapp >> compose-contents.txt
+$OSTREE compose -b some-compose-from-file -s 'from file' -F compose-contents.txt
+rm -rf some-compose-checkout
+$OSTREE checkout some-compose-from-file some-compose-checkout
+cd some-compose-checkout
+assert_file_has_content ./usr/bin/bar 'updated bar ELF file'
+echo 'ok recompose from file'